package com.wsm.springai.studydemo2.tools;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tools")
public class ToolsController {
    ChatClient chatClient;

    public ToolsController(ChatClient.Builder chatClientBuilder,
                           ToolService toolService,
                           ChatMemory chatMemory) {
        chatClient = chatClientBuilder.
                defaultTools(toolService)
                .defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build())
                .build();
    }


    @RequestMapping("/get")
    public String tool(@RequestParam(value = "message" , defaultValue = "hello") String message) {
        return chatClient.prompt().user(message).call().content();
    }

}
